var a = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        info: {},
        activeName: 0,
        dataList: [],
        titleArr: [ "观看记录", "奖励记录", "分享记录" ],
        isLoadMore: !0
    },
    onLoad: function(a) {
        this.init(), this.getData();
    },
    init: function() {
        var a = this;
        this.data.titleArr.forEach(function(t, e) {
            a.data.dataList.push({
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: []
            });
        }), this.handleClick();
    },
    getData: function() {
        var a = this, e = t.getNetAddresss("plugin.ad-serving.frontend.advertisers.index.getOrderDetail");
        t._postNetWork({
            url: e,
            data: {
                advertising_id: this.options.id
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    info: e.data
                }) : console.log(e);
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    handleClick: function(e) {
        var i = this;
        e && e.detail && this.setData({
            activeName: e.detail.index
        });
        var s = t.getNetAddresss("plugin.ad-serving.frontend.advertisers.index.getOrderDetailLog");
        t._getNetWork({
            url: s,
            data: {
                advertising_id: this.options.id,
                log_type: Number(this.data.activeName) + 1
            },
            success: function(t) {
                var e, s = t.data;
                1 == s.result ? i.setData((a(e = {}, "dataList[" + i.data.activeName + "].isLoadMore", !0), 
                a(e, "dataList[" + i.data.activeName + "].total_page", s.data.last_page), a(e, "dataList[" + i.data.activeName + "].list", s.data.data), 
                e)) : wx.showToast({
                    title: s.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.dataList[this.data.activeName].isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    _getMoreData: function() {
        var e = this;
        if (this.setData(a({}, "dataList[" + e.data.activeName + "].isLoadMore", !1)), !(this.data.dataList[this.data.activeName].page >= this.data.dataList[this.data.activeName].total_page)) {
            this.data.dataList[this.data.activeName].page = this.data.dataList[this.data.activeName].page + 1;
            var i = t.getNetAddresss("plugin.ad-serving.frontend.advertisers.index.getOrderDetailLog");
            i += "&page=" + this.data.dataList[this.data.activeName].page, t._getNetWork({
                url: i,
                data: {
                    advertising_id: this.options.id,
                    log_type: Number(this.data.activeName) + 1
                },
                success: function(t) {
                    var i = t.data;
                    if (1 == i.result) {
                        var s, d = i.data;
                        e.setData((a(s = {}, "dataList[" + e.data.activeName + "].isLoadMore", !0), a(s, "dataList[" + e.data.activeName + "].list", e.data.dataList[e.data.activeName].list.concat(d.data)), 
                        s));
                    } else {
                        var o;
                        e.setData((a(o = {}, "dataList[" + e.data.activeName + "].isLoadMore", !1), a(o, "dataList[" + e.data.activeName + "].page", e.data.dataList[e.data.activeName].page - 1), 
                        o));
                    }
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    onShareAppMessage: function() {}
});